import request from "../utils/request";

// 获取设备列表
export const getDevices = (params = {}) => {
  const { page = 1, size = 10, status, keyword } = params;
  const queryParams = { page, size };
  if (status) queryParams.status = status;
  if (keyword) queryParams.keyword = keyword;
  return request({
    url: "/api/devices",
    method: "get",
    params: queryParams
  });
};

// 获取设备详情
export const getDeviceDetail = (deviceId) => {
  return request({
    url: `/api/devices/${deviceId}`,
    method: "get"
  });
};

// 添加设备
export const addDevice = (deviceData) => {
  return request({
    url: "/api/devices",
    method: "post",
    data: deviceData
  });
};

// 更新设备信息
export const updateDevice = (deviceId, deviceData) => {
  return request({
    url: `/api/devices/${deviceId}/status`,
    method: "put",
    data: deviceData
  });
};

// 删除设备
export const deleteDevice = (deviceId) => {
  return request({
    url: `/api/devices/${deviceId}`,
    method: "delete"
  });
};

// 获取设备状态
export const getDeviceStatus = () => {
  return request({
    url: "/api/devices/status",
    method: "get"
  });
};

// 获取可用设备列表
export const getAvailableDevices = () => {
  return request({
    url: "/api/devices/available",
    method: "get"
  });
};

// 根据状态获取设备
export const getDevicesByStatus = (status) => {
  return request({
    url: "/api/devices",
    method: "get",
    params: { status }
  });
};

// 刷新设备列表
export const refreshDevices = () => {
  return request({
    url: "/api/devices/refresh",
    method: "get"
  });
};